home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue45 / Message / SpyConfigure.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2000-11-02  |  3.3 KB  |  130 lines

  1. unit SpyConfigure;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   StdCtrls, SpyEngine, ExtCtrls;
  8.  
  9. type
  10.   TfrmSpyConfigure = class(TForm)
  11.     gbOptions1: TGroupBox;
  12.     cbWndMsgs: TCheckBox;
  13.     cbCNMsgs: TCheckBox;
  14.     cbCMMsgs: TCheckBox;
  15.     pnlRight: TPanel;
  16.     btnOK: TButton;
  17.     btnCancel: TButton;
  18.     lblControl: TLabel;
  19.     cbControl: TComboBox;
  20.     rgMonitorFrom: TRadioGroup;
  21.     gbFilters: TGroupBox;
  22.     cbConsecutiveMessages: TCheckBox;
  23.     cbHeavyHitters: TCheckBox;
  24.     procedure FormShow(Sender: TObject);
  25.     procedure FormDestroy(Sender: TObject);
  26.     procedure btnOKClick(Sender: TObject);
  27.   private
  28.     MessageSpy: TMessageSpy;
  29.     ControlList: TStringList;
  30.     procedure LoadComboBox;
  31.     procedure SetControlsFromOptions;
  32.     procedure SetOptionsFromControls;
  33.   public
  34.   end;
  35.  
  36. var
  37.   frmSpyConfigure: TfrmSpyConfigure;
  38.  
  39. implementation
  40.  
  41. {$R *.DFM}
  42.  
  43. procedure TfrmSpyConfigure.btnOKClick(Sender: TObject);
  44. begin
  45.   SetOptionsFromControls;
  46.   Close;
  47. end;
  48.  
  49. procedure TfrmSpyConfigure.FormDestroy(Sender: TObject);
  50. begin
  51.   ControlList.Free;
  52. end;
  53.  
  54. procedure TfrmSpyConfigure.FormShow(Sender: TObject);
  55. begin
  56.   ControlList := TStringList.Create;
  57.   MessageSpy := TMessageSpy(Owner);
  58.   SetControlsFromOptions;
  59. end;
  60.  
  61. procedure TfrmSpyConfigure.LoadComboBox;
  62. var
  63.   I: Integer;
  64.   F: TCustomForm;
  65.   C: TComponent;
  66. begin
  67.   F := TCustomForm(MessageSpy.Owner);
  68.   ControlList.AddObject('<None>', nil);
  69.   ControlList.AddObject(F.Name, F);
  70.   for I := 0 to F.ComponentCount - 1 do
  71.   begin
  72.     C := F.Components[I];
  73.     if C is TMessageSpy then
  74.       // skip it
  75.     else if C is TControl then
  76.     begin
  77.       if C.Name <> '' then
  78.         ControlList.AddObject(C.Name, C)
  79.       else
  80.         ControlList.AddObject('anonymous ' + C.ClassName, C);
  81.     end;
  82.   end;
  83.   cbControl.Items.Assign(ControlList);
  84. end;
  85.  
  86. procedure TfrmSpyConfigure.SetControlsFromOptions;
  87. var
  88.   I: Integer;
  89. begin
  90.   cbWndMsgs.Checked := mtWindowsMessage in MessageSpy.MessageTypes;
  91.   cbCNMsgs.Checked := mtCN_Message in MessageSpy.MessageTypes;
  92.   cbCMMsgs.Checked := mtCM_Message in MessageSpy.MessageTypes;
  93.   cbConsecutiveMessages.Checked := MessageSpy.FilterConsecutiveMessages;
  94.   cbHeavyHitters.Checked := MessageSpy.FilterHeavyHitters;
  95.   case MessageSpy.HookType of
  96.     htWndProc:    rgMonitorFrom.ItemIndex := 0;
  97.     htDispatch:   rgMonitorFrom.ItemIndex := 1;
  98.     htBoth:       rgMonitorFrom.ItemIndex := 2;
  99.   end;
  100.   LoadComboBox;
  101.   cbControl.ItemIndex := 0;
  102.   I := ControlList.IndexOfObject(MessageSpy.Hookee);
  103.   if I <> -1 then
  104.     cbControl.ItemIndex := I;
  105. end;
  106.  
  107. procedure TfrmSpyConfigure.SetOptionsFromControls;
  108. var
  109.   MT: TMessageTypes;
  110. begin
  111.   MT := [];
  112.   if cbWndMsgs.Checked then
  113.     Include(MT, mtWindowsMessage);
  114.   if cbCNMsgs.Checked then
  115.     Include(MT, mtCN_Message);
  116.   if cbCMMsgs.Checked Then
  117.     Include(MT, mtCM_Message);
  118.   MessageSpy.MessageTypes := MT;
  119.   MessageSpy.FilterConsecutiveMessages := cbConsecutiveMessages.Checked;
  120.   MessageSpy.FilterHeavyHitters := cbHeavyHitters.Checked;
  121.   case rgMonitorFrom.ItemIndex of
  122.     0: MessageSpy.HookType := htWndProc;
  123.     1: MessageSpy.HookType := htDispatch;
  124.     2: MessageSpy.HookType := htBoth;
  125.   end;
  126.   MessageSpy.Hookee := TControl(ControlList.Objects[cbControl.ItemIndex]);
  127. end;
  128.  
  129. end.
  130.